package com.calsoft.Hops_Mobile_Tablet;
/*
 * User: Minh Diep
 * Date: 6/26/13
 * Time: 1:59 PM
 */


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.calsoft.Hops_Mobile_Tablet.util.SharedPrefs;

public class HomeFragment extends Fragment {

    HomeSectionsPagerAdapter homeSectionsPagerAdapter;
    ViewPager viewPager;
    private SharedPrefs sharedPrefs;

    public HomeFragment() {
        // Empty constructor required for fragment subclasses
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);
        getActivity().setTitle("Schedule");
        sharedPrefs = new SharedPrefs(getActivity().getApplicationContext());
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        int currentSubPage = sharedPrefs.getInt(SharedPrefs.CURRENT_SUB_PAGE, 0);
        viewPager.setCurrentItem(currentSubPage);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        homeSectionsPagerAdapter = new HomeSectionsPagerAdapter(getChildFragmentManager());
        viewPager = (ViewPager) view.findViewById(R.id.pager);
        viewPager.setAdapter(homeSectionsPagerAdapter);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) {
            }

            @Override
            public void onPageSelected(int i) {
                sharedPrefs.putInt(SharedPrefs.CURRENT_SUB_PAGE, i);
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
    }

    @Override
    public void onStop() {
        super.onStop();
    }

}